home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / termsorc.lha / Extras / Source / gtlayout-source.lha / LTP_SelectKeys.c < prev    next >
C/C++ Source or Header  |  1995-09-24  |  4KB  |  230 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1995 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. */
  6.  
  7. #include "gtlayout_global.h"
  8.  
  9. #ifdef DO_PICKSHORTCUTS
  10. VOID __regargs
  11. LTP_SelectKeys(LayoutHandle *handle,ObjectNode *group)
  12. {
  13.     UBYTE         bunch;
  14.     ObjectNode    *node;
  15.     ULONG         page;
  16.     STRPTR        *lines = NULL;
  17.  
  18.     SCANPAGE(group,node,page)
  19.     {
  20.         bunch = 0;
  21.  
  22.         switch(node -> Type)
  23.         {
  24.             case GROUP_KIND:
  25.  
  26.                 LTP_SelectKeys(handle,node);
  27.                 break;
  28.  
  29.             case TEXT_KIND:
  30.  
  31.                 if(!node -> Special . Text . UsePicker)
  32.                     break;
  33.  
  34.             case FRACTION_KIND:
  35.             case PASSWORD_KIND:
  36.             case STRING_KIND:
  37.  
  38.                 if(node -> Special . String . UsePicker)
  39.                     bunch = 255;
  40.  
  41.             case BUTTON_KIND:
  42.  
  43.                 if(node -> Type == BUTTON_KIND)
  44.                 {
  45. #ifdef OLD_STYLE_DEFAULT_KEY
  46.                     if(node -> Key && node -> Special . Button . Lines)
  47. #else
  48.                     if(node -> Key && (node -> Special . Button . Lines || node -> Special . Button . ReturnKey))
  49. #endif
  50.                     {
  51.                         BOOL    GotIt = FALSE;
  52.                         WORD    i,j,len;
  53.                         STRPTR    label;
  54.  
  55.                         if(node -> Special . Button . Lines)
  56.                             lines = node -> Special . Button . Lines;
  57.  
  58.                         for(j = 0 ; ; j++)
  59.                         {
  60.                             if(lines)
  61.                             {
  62.                                 if(!(label = lines[j]))
  63.                                     break;
  64.                             }
  65.                             else
  66.                                 label = node -> Label;
  67.  
  68.                             len = strlen(label);
  69.  
  70.                             for(i = 0 ; !GotIt && i < len ; i++)
  71.                             {
  72.                                 if(label[i] == '_' && i != len - 1)
  73.                                 {
  74.                                     STRPTR NewLabel = LTP_Alloc(handle,len);
  75.  
  76.                                     if(!NewLabel)
  77.                                         return;
  78.                                     else
  79.                                     {
  80.                                         if(i)
  81.                                             CopyMem(label,NewLabel,i);
  82.  
  83.                                         CopyMem(&label[i + 1],&NewLabel[i],len - i);
  84.  
  85.                                         if(lines)
  86.                                             lines[j] = NewLabel;
  87.                                         else
  88.                                             node -> Label = NewLabel;
  89.  
  90.                                         node -> Special . Button . KeyStroke = &NewLabel[i];
  91.  
  92.                                         GotIt = TRUE;
  93.                                     }
  94.                                 }
  95.                             }
  96.  
  97.                             if(!lines || GotIt)
  98.                                 break;
  99.                         }
  100.  
  101.                         break;
  102.                     }
  103.  
  104.                     if(!node -> NoKey && node -> Special . Button . Lines)
  105.                         lines = node -> Special . Button . Lines;
  106.                 }
  107.  
  108.             case BOOPSI_KIND:
  109.             case CHECKBOX_KIND:
  110.             case INTEGER_KIND:
  111.  
  112.                 bunch++;
  113.  
  114.             case LISTVIEW_KIND:
  115.             case MX_KIND:
  116.             case CYCLE_KIND:
  117.             case PALETTE_KIND:
  118.             case SCROLLER_KIND:
  119.             case SLIDER_KIND:
  120. #if defined(DO_POPUP_KIND) && defined(DO_BOOPSI_KIND)
  121.             case POPUP_KIND:
  122. #endif
  123. #if defined(DO_TAB_KIND) && defined(DO_BOOPSI_KIND)
  124.             case TAB_KIND:
  125. #endif
  126. #ifdef DO_LEVEL_KIND
  127.             case LEVEL_KIND:
  128. #endif    /* DO_LEVEL_KIND */
  129. #ifdef DO_TAPEDECK_KIND
  130.             case TAPEDECK_KIND:
  131. #endif    /* DO_TAPEDECK_KIND */
  132.  
  133.                 bunch++;
  134.  
  135.                 if(node -> Label && !node -> Key && !node -> NoKey)
  136.                 {
  137.                     WORD    i,len,code,glyph;
  138.                     STRPTR    label;
  139.  
  140.                     do
  141.                     {
  142.                         if(lines)
  143.                         {
  144.                             if(!(*lines))
  145.                                 break;
  146.  
  147.                             label = *lines;
  148.                         }
  149.                         else
  150.                             label = node -> Label;
  151.  
  152.                         len = strlen(label);
  153.  
  154.                         for(i = 0 ; i < len ; i++)
  155.                         {
  156.                             glyph    = ToLower(label[i]);
  157.                             code    = -1;
  158.  
  159.                             if(bunch == 1)    // Support increment & decrement
  160.                             {
  161.                                 if(LTP_Keys[0][glyph] && LTP_Keys[1][glyph])
  162.                                     code = LTP_Keys[0][glyph];
  163.                             }
  164.                             else
  165.                             {
  166.                                 if(bunch == 2)
  167.                                 {
  168.                                     if(LTP_Keys[0][glyph])
  169.                                         code = LTP_Keys[0][glyph];
  170.                                     else
  171.                                     {
  172.                                         if(LTP_Keys[1][glyph] && LTP_Keys[0][glyph])
  173.                                         {
  174.                                             if(ToLower(LTP_Keys[1][glyph]) == glyph)
  175.                                                 code = LTP_Keys[0][glyph];
  176.                                         }
  177.                                     }
  178.                                 }
  179.                             }
  180.  
  181.                             if(code != -1 && !handle -> Keys[code])
  182.                             {
  183.                                 if(lines)
  184.                                 {
  185.                                     node -> Special . Button . KeyStroke = &label[i];
  186.  
  187.                                     node -> Key = code;
  188.  
  189.                                     handle -> Keys[code] = handle -> Keys[LTP_Keys[1][code]] = TRUE;
  190.  
  191.                                     lines = NULL;
  192.  
  193.                                     break;
  194.                                 }
  195.                                 else
  196.                                 {
  197.                                     STRPTR newLabel;
  198.  
  199.                                     if(newLabel = LTP_Alloc(handle,len + 2))
  200.                                     {
  201.                                         node -> Label    = newLabel;
  202.                                         node -> Key    = code;
  203.  
  204.                                         if(i)
  205.                                             CopyMem(label,newLabel,i);
  206.  
  207.                                         newLabel[i] = '_';
  208.  
  209.                                         CopyMem(label + i,&newLabel[i + 1],len - i);
  210.  
  211.                                         handle -> Keys[code] = handle -> Keys[LTP_Keys[1][code]] = TRUE;
  212.  
  213.                                         break;
  214.                                     }
  215.                                 }
  216.                             }
  217.                         }
  218.  
  219.                         if(lines)
  220.                             lines++;
  221.                     }
  222.                     while(lines);
  223.                 }
  224.  
  225.                 break;
  226.         }
  227.     }
  228. }
  229. #endif
  230.